package com.dudu.dao;

import java.sql.Connection;
import java.util.List;

import net.sf.json.JSONObject;

import com.dudu.bean.StatusCallId;

import core.CoreDao;
import core.db.DBConnectionUtil;

public class StatusCallIdDao {

	public static void main(String[] args) {

	
	}
	
	public int insert(CoreDao dao, StatusCallId bean) {

		Connection con = null;
		int result = -1;
		try {
			con = DBConnectionUtil.getDBConnection("emate1");
			StringBuffer sql = new StringBuffer("INSERT INTO t_status_callId(phone, callId, addTime,note )");
			sql.append("VALUES(?, ?,sysDate(),?)");

			List<JSONObject> list = dao.serviceJsonSql(
					con,
					sql.toString(),
					new Object[] { 
						
						bean.getPhone(),
						bean.getCallId(),
						bean.getNote()
					
					});

			JSONObject obj = list.get(0);
			result = obj.optInt("result");

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			DBConnectionUtil.close(null, null, con);
		}
		return result;
	}

	

	public StatusCallId query(CoreDao dao, String phone) {

		Connection con = null;
		StatusCallId result = null;

		try {
			
			con = DBConnectionUtil.getDBConnection("emate1");

			StringBuffer sql = new StringBuffer("select * from t_status_callId where phone = ?");
			
			List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(),
					new Object[] { 
				
				phone
			});
			
			if (list != null && list.size() > 0) {
				List<StatusCallId> items = dao.covertToBean(list, StatusCallId.class);
				result = items.get(0);
			}

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			DBConnectionUtil.close(null, null, con);
		}
		return result;
		
	}
	
	
	public int delete(CoreDao dao, String phone) {
		//数据库连接
		Connection con = null;
		int result = -1;
		try {
			//获取数据库连接
			con = DBConnectionUtil.getDBConnection("emate1");
			//拼写sql
			StringBuffer sql = new StringBuffer(" delete from t_status_callId where phone =?");
			sql.append("?");
			//执行sql
			List<JSONObject> list = dao.serviceJsonSql(con, sql.toString(),
					new Object[] { phone });

			if (list != null && list.size() > 0) {
				JSONObject obj = list.get(0);
				result = obj.optInt("result");
			}

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			DBConnectionUtil.close(null, null, con);
		}
		return result;
	}
	
}
